function getMenuItem(itemData){
	 var item = $("<li>");
	 var link=$("<a>", {href:  itemData.url,html: itemData.text});
	 var arrow=$("<span>", {class:  "fa arrow"});
	 var img='';
	 if(itemData.text=='System'){
	 	img=$("<img>", {src:  img_system});
	 }else if(itemData.text=='Content'){
	 	img=$("<img>", {src:  img_content});
	 }else if(itemData.text=='Plugins'){
	 	img=$("<img>", {src:  img_plugin});
	 }else if(itemData.text=='Extensions'){
	 	img=$("<img>", {src:  img_extension});
	 }else if(itemData.text=='Modules'){
	 	img=$("<img>", {src:  img_module});
	 }else if(itemData.text=='Widgets'){
	 	img=$("<img>", {src:  img_widget});
	 }else{
	 	img=$("<img>", {src:  img_system});
	 }
	 if(itemData.sub){
            item.append(link.append(arrow).prepend(img));
        }else{
        	item.append(link);
        }
        if (itemData.sub) {
            var subList = $("<ul>",{class:"nav nav-second-level"});
            $.each(itemData.sub, function () {
                subList.append(getMenuItem(this));
            });
            item.append(subList);
        }
        return item;
}
$.ajax({
	type	   : "GET",
	url		   : menulink,
	dataType : "json",
    /*beforeSend: function(xhr, settings) {
        $("#Li2").find("ul").remove();
    },*/		  
	success	 : function(data){
	     var $menu = $("#side-menu");
    $.each(data.menu, function () {
        $menu.append(
            getMenuItem(this)
        );
    });
    $.getScript('//cdn.jsdelivr.net/bootstrap.metismenu/1.1.0/js/metismenu.min.js');
    $(function() {
    	$menu.metisMenu();
    });
	}
});